// pages/Special/Special.js
const SERVER = require('../../utils/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    lists:[],
    actv:0,//收藏
    guan:0,//关注
    tabsList: ['拍品', '专场介绍'],
    tabsLists: ['图录号小-大', '估价低-高','大图'],
    tabsId: 0,
    tabsIds: 0,
    inut:'',
  },
  tabs(e) {
    this.setData({
      tabsId: e.currentTarget.dataset.id
    })
  },
  tabss(e) {
    console.log(this.data.tabsIds)
    this.setData({
      tabsIds: e.currentTarget.dataset.id
    })
  },
   //点击搜索按钮
   binbut(){
    var that=this
    let param = {
      size : 10,
      orderBy1 : 1,
      current : 1,
      indexType:2,
      searchStr:this.data.inut,
    }
    wx.request({//首页数据
      url: '' + SERVER.SERVER_DIMAIN + '/customer/search/getLotList', 
      data: JSON.stringify(param),
      header: {
        'content-type': 'application/json' ,
        "TENANT-ID":"2",
        "Authorization":"Basic YXBwOmFwcA==",
        "DEVICE_TYPE":'IOS'
      },
      method: 'post',
      success: function (res) {
        console.log(res)
       that.setData({
         lists:res.data.data.records
       })
      }
    });
  },
  search(e){//获取input值
    this.setData({
      inut:e.detail.value
    })
   },
  follow(e){
    if(this.data.guan==0){
      let pamers={
        followType:1,
        specLotId:e.currentTarget.dataset.id
      }
     var that=this
      wx.request({//首页数据
        url: '' + SERVER.SERVER_DIMAIN + '/customer/follow/addfollow', 
        data: JSON.stringify(pamers),
        header: {
          'content-type': 'application/json' ,
          "TENANT-ID":"2",
          "Connection":'Keep-alive',
          "Accept-Encoding":'gzip,deflate,br',
          "Authorization":"Bearer "+wx.getStorageSync('token'),
          "DEVICE_TYPE":'IOS'
        },
        method: 'post',
        success: function (res) {
          if(res.data.msg=='操作成功'){
            that.setData({
              guan:1
            })
            wx.showToast({

              title: '关注成功',
         
              icon: 'success',
         
              duration: 2000//持续的时间
         
            })
          }
        }
      });
    }
    else{
      let pamers={
        followType:1,
        specLotId:e.currentTarget.dataset.id
      }
     var that=this
      wx.request({//首页数据
        url: '' + SERVER.SERVER_DIMAIN + '/customer/follow/removefollow', 
        data: JSON.stringify(pamers),
        header: {
          'content-type': 'application/json' ,
          "TENANT-ID":"2",
          "Connection":'Keep-alive',
          "Accept-Encoding":'gzip,deflate,br',
          "Authorization":"Bearer "+wx.getStorageSync('token'),
          "DEVICE_TYPE":'IOS'
        },
        method: 'post',
        success: function (res) {
          if(res.data.msg=='操作成功'){
            that.setData({
              guan:0
            })
            wx.showToast({

              title: '取消成功',
         
              icon: 'success',
         
              duration: 2000//持续的时间
         
            })
          }
        }
      });
    }
      },
      //点击收藏
      show(e){
        if(this.data.actv==0){
          let pamers={
            favType:1,
            specLotId:e.currentTarget.dataset.id
          }
         var that=this
          wx.request({//首页数据
            url: '' + SERVER.SERVER_DIMAIN + '/customer/favoritesspec/addfav', 
            data: JSON.stringify(pamers),
            header: {
              'content-type': 'application/json' ,
              "TENANT-ID":"2",
              "Connection":'Keep-alive',
              "Accept-Encoding":'gzip,deflate,br',
              "Authorization":"Bearer "+wx.getStorageSync('token'),
              "DEVICE_TYPE":'IOS'
            },
            method: 'post',
            success: function (res) {
              that.setData({
                actv:res.data.msg
              })
              wx.showToast({

                title: '收藏成功',
           
                icon: 'success',
           
                duration: 2000//持续的时间
           
              })
            }
          });
        }else{
          
          let pamers={
            favType:1,
            specLotId:e.currentTarget.dataset.id
          }
         var that=this
          wx.request({//首页数据
            url: '' + SERVER.SERVER_DIMAIN + '/customer/favoritesspec/removefav', 
            data: JSON.stringify(pamers),
            header: {
              'content-type': 'application/json' ,
              "TENANT-ID":"2",
              "Connection":'Keep-alive',
              "Accept-Encoding":'gzip,deflate,br',
              "Authorization":"Bearer "+wx.getStorageSync('token'),
              "DEVICE_TYPE":'IOS'
            },
            method: 'post',
            success: function (res) {
              wx.showToast({

                title: '取消成功',
           
                icon: 'success',
           
                duration: 2000//持续的时间
           
              })
              
              that.setData({
                actv:0
              })
            }
          });
        }
      
      },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that=this
    this.binbut()
    wx.request({//首页数据
      url: '' + SERVER.SERVER_DIMAIN + '/customer/spec/specdetails', 
      data: {
        specId:options.id
      },
      header: {
        'content-type': 'application/json' 
      },
      method: 'get',
      success: function (res) {
        console.log(res)
        that.setData({
          list:res.data.data
        })
        
     
       
      }
    });
  },
  gotowangljt(){
    wx.navigateTo({
      url: '/pages/wangljt/wangljt'
    })
  },
  gotobaozj(){
    wx.navigateTo({
      url: '/pages/baozj/baozj'
    })
  },
  makeCall: function () {
    var telephone = '010-65903765'//手机号
    var fixed_telephone = '010-65903178'//固话
    if (telephone && fixed_telephone && telephone != fixed_telephone){
        wx.showActionSheet({
          itemList: [telephone, fixed_telephone],
          success(res) {
            if (res.tapIndex === 0) {
              wx.makePhoneCall({ //点击确定按钮  调用小程序拨打电话的api  
                phoneNumber: telephone,//从后台获取到的电话号码
                success: function () {
                  console.log('拨打电话成功' + telephone)
                },
                fail: function () {
                  console.log("拨打电话失败")
                }
              })
            } else if (res.tapIndex === 1) {
              wx.makePhoneCall({ //点击确定按钮  调用小程序拨打电话的api  
                phoneNumber: fixed_telephone,//从后台获取到的电话号码
                success: function () {
                  console.log('拨打电话成功' + fixed_telephone )
                },
                fail: function () {
                  console.log("拨打电话失败")
                }
              })
            }
          },
          fail(res) {
            console.log("拨打电话失败")
          }
        })
  
    } else if (telephone === fixed_telephone){
      //弹出dialog弹出框
      wx.showModal({
        content: "确认拨打" + fixed_telephone + "吗",
        confirmColor: '#2EA7E0',
        success(res) {
          if (res.cancel) {
            // 用户点击了取消属性的按钮 
            return false
          } else if (res.confirm) {
            wx.makePhoneCall({ //调用小程序拨打电话的api
              phoneNumber: fixed_telephone, //获取到的电话号码
              success: function () {
                console.log('拨打电话成功')
              },
              fail: function () {
                console.log("拨打电话失败")
              }
            })
          }
        }
      })
    } else if (!telephone){
      //弹出dialog弹出框
      wx.showModal({
        content: "确认拨打" + fixed_telephone + "吗",
        confirmColor: '#2EA7E0',
        success(res) {
          if (res.cancel) {
            // 用户点击了取消属性的按钮 
            return false
          } else if (res.confirm) {
            wx.makePhoneCall({ //调用小程序拨打电话的api
              phoneNumber: fixed_telephone, //获取到的电话号码
              success: function () {
                console.log('拨打电话成功')
              },
              fail: function () {
                console.log("拨打电话失败")
              }
            })
          }
        }
      })
    } else if (!fixed_telephone){
      //弹出dialog弹出框
      wx.showModal({
        content: "确认拨打" + telephone + "吗",
        confirmColor: '#2EA7E0',
        success(res) {
          if (res.cancel) {
            // 用户点击了取消属性的按钮 
            return false
          } else if (res.confirm) {
            wx.makePhoneCall({ //调用小程序拨打电话的api
              phoneNumber: telephone, //获取到的电话号码
              success: function () {
                console.log('拨打电话成功')
              },
              fail: function () {
                console.log("拨打电话失败")
              }
            })
          }
        }
      })
    } else if (!fixed_telephone && !fixed_telephone){
      wx.showModal({
        content: "暂无联系电话",
        confirmColor: '#2EA7E0',
        showCancel: false,//不显示取消按钮
        success(res) {
          if (res.confirm) {
             return false
          }
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  onShareTimeline(res){
    console.log(res)
    return {
      title: '北京程轩小程序',
      path: '../index/index',
      imageUrl:''
    }

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})